﻿<UserControl x:Class="GestionComptes"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:OMANE.Modules.CRT"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    <Grid Name="mainGrid" >
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="5" />
            <ColumnDefinition Width="Auto" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <DataGrid Name="comptesDGrid" SelectedItem="{Binding Path=SelectedCompte}" ItemsSource="{Binding TABLE_COMPTES}"  IsSynchronizedWithCurrentItem="True" Grid.Row="1" AutoGenerateColumns="False" CanUserReorderColumns="False" CanUserDeleteRows="False" >
            <DataGrid.Columns>
                <DataGridTextColumn IsReadOnly="True" Header="ID COMPTE" Binding="{Binding ID}"/>
                <DataGridTextColumn Header="NOM COMPTE" Binding="{Binding NOM}"/>
                <DataGridTextColumn Header="DESCRIPTION COMPTE" Binding="{Binding DESCRIPTION}"/>
            </DataGrid.Columns>
        </DataGrid>
        <DataGrid  Grid.Row="2" AutoGenerateColumns="False" IsSynchronizedWithCurrentItem="True"  CanUserReorderColumns="False" CanUserAddRows="False" ItemsSource="{Binding TABLE_COMPTES/REL_COMPTE_DESC}" AllowDrop="True" CanUserDeleteRows="False">
            <DataGrid.Columns>
                <DataGridTemplateColumn>
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <Button Content="Editer" />
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
                <DataGridTextColumn IsReadOnly="True" Header="ID POSTE" Binding="{Binding ID_POSTE}"/>
                <DataGridTextColumn Header="NOM POSTE"  IsReadOnly="True">
                    <DataGridTextColumn.Binding>
                        <Binding>
                            <Binding.Converter>
                                <local:GestionComptesIDPosteToNomPosteConverter />
                            </Binding.Converter>
                        </Binding>
                    </DataGridTextColumn.Binding>
                </DataGridTextColumn>
                <DataGridTextColumn IsReadOnly="True"  Width="600" Header="FORMULE DE CALCUL DU POSTE" Binding="{Binding FORMULE}">
                	<DataGridTextColumn.ElementStyle>
                		<Style TargetType="{x:Type TextBlock}">
                			<Setter Property="Margin" Value="2,0"/>
							<Setter Property="TextWrapping" Value="Wrap"/>
                		</Style>
                	</DataGridTextColumn.ElementStyle>
                </DataGridTextColumn>

            </DataGrid.Columns>
        </DataGrid>


        <GridSplitter Name="Splitter" Grid.Row="1" Grid.Column="1" Grid.RowSpan="2" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
        <Expander Name="Expander" ExpandDirection="Right" Grid.Row="1" Grid.Column="2" Grid.RowSpan="2" >
            <Expander.Header>
                <TextBlock Text="Postes" Margin="5,15,5,5">
                	<TextBlock.LayoutTransform>
                		<TransformGroup>
                			<ScaleTransform/>
                			<SkewTransform/>
                			<RotateTransform Angle="90"/>
                			<TranslateTransform/>
                		</TransformGroup>
                	</TextBlock.LayoutTransform>
                </TextBlock>
            </Expander.Header>
            <DataGrid Name="postesDGrid"   SelectionUnit="FullRow" SelectionMode="Single" ItemsSource="{Binding TABLE_POSTES}" CanUserReorderColumns="False" CanUserSortColumns="False" AutoGenerateColumns="False" CanUserDeleteRows="False">
                <DataGrid.Columns>
                    <DataGridTemplateColumn IsReadOnly="True">
                        <DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <Button Content="+" Command="{Binding RelativeSource={RelativeSource AncestorType=local:GestionComptes}, Path=DataContext.AjouterPoste}" CommandParameter="{Binding RelativeSource={RelativeSource AncestorType=DataGrid}, Path=SelectedItem}">
                                    <Button.Visibility>
                                        <Binding RelativeSource="{RelativeSource AncestorType=DataGridRow}" Path="IsSelected">
                                            <Binding.Converter>
                                                <local:GestionComptesPotsteRowToVisibilityConverter />
                                            </Binding.Converter>
                                        </Binding>
                                    </Button.Visibility>
                                </Button>
                            </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>
                    </DataGridTemplateColumn>
                    <DataGridTextColumn IsReadOnly="True" Header="ID POSTE" Binding="{Binding ID}"/>
                    <DataGridTextColumn Header="NOM POSTE" Binding="{Binding NOM}"/>
                    <DataGridTextColumn Header="DESCRIPTION POSTE" Binding="{Binding DESCRIPTION}"/>
                </DataGrid.Columns>
            </DataGrid>
        </Expander>
        
    </Grid>
</UserControl>
